/*************************************************************************
	> File Name: sigaction_2.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: Sat 21 Jun 2014 04:05:47 PM CST
 ************************************************************************/
// this example contains the use of flag: SA_SIGINFO
// man 2 sigaction

//#define _POSIX_C_SOURCE 199309
/*很奇怪,上面_POSIX_C_SOURCE 199309的定义可有可无,
这个程序在openSUSE Tumbleweed上运行会出现段错误
在ubuntu14.04上运行正常, SA_SIGINFO真是个奇怪的东西
*/
#include<stdio.h>
#include<signal.h>
#include<unistd.h>

void dealing(int sig, siginfo_t *info, void *ucontext)
{
    if(info->si_signo==SIGINT)
    printf("counght SIGINT\n");
    printf("cought %d\n",info->si_signo);
}

int main(int argc, char *argv[])
{
    struct sigaction act;

    if(sigfillset(&act.sa_mask)==-1)
    {
        perror("sigemptyset:");
            _exit(SIGTERM);
    }
    
    act.sa_sigaction=dealing;
    act.sa_flags=SA_SIGINFO|SA_RESTART;

    if(sigaction(SIGINT,&act,NULL)==-1)
    {
        perror("sigaction with SA_SIGINFO:");
        _exit(SIGINT);
    }
    for(;;);
    pause();
}
